package com.fzh.wangxiao.utils;


import java.math.BigDecimal;
import java.math.RoundingMode;

public class CalculatorUtils {

    public static String fixedInvestment(double money,double rate, int years){
        rate = 1+(rate/100);
        for(int i = 1 ; i<=years; i++){
            money = (money * rate);
        }
        return money+"";
    }

    public static String fixedMonthlyInvestment(double money,double rate, int month){
        rate = 1+(rate/12/100);
        System.out.println(rate);
        double amount = 0;
        for(int i = 1 ; i<=month; i++){
            amount = amount+money;
            amount = (amount * rate);
            System.out.println("money:"+format1(amount));
        }
        return format1(amount);
    }


    public static String format1(double value) {
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(2, RoundingMode.HALF_UP);
        return bd.toString();
    }



}
